﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Zen4SyncOrchestratorServices;

namespace Zen4SyncDashboard
{
    internal static class ExtensionMethods
    {
        internal static void Call(this ChannelFactory<IOrchestratorServices> client, Action<IOrchestratorServices> action)
        {
            try
            {
                if (client.State == CommunicationState.Closed)
                {
                    client.Open();
                }

                IOrchestratorServices services = client.CreateChannel();
                action(services);
            }
            catch (Exception exception)
            {
                client.Abort();
                throw exception;
            }
        }
    }
}
